//
// Created by Tonser on 2020/5/16.
//

#ifndef INCLUDE_SERIAL_UTILS_H
#define INCLUDE_SERIAL_UTILS_H

#include <vector>
#include <serial/serial.h>

#define  BYTE0(dwTemp)       ( *( (uint8_t *)(&dwTemp)    ) )
#define  BYTE1(dwTemp)       ( *( (uint8_t *)(&dwTemp) + 1) )
#define  BYTE2(dwTemp)       ( *( (uint8_t *)(&dwTemp) + 2) )
#define  BYTE3(dwTemp)       ( *( (uint8_t *)(&dwTemp) + 3) )

// used to save bytes
#define DATA_FRAM struct  __attribute__ ((__packed__))
#define SCALE 10000.0
typedef std::vector<uint8_t> Buffer;

/***
 * judge if a contain b  ==>  b ?== (a & b)
 * @param a uchar origin data
 * @param b uchar
 * @return
 */
inline bool contain(u_char a, u_char b) {
    return b == (a & b);
}

/***
 * byte operation a&b  ==> a = a | b
 * @param a uchar origin data
 * @param b
 */
inline void byte_add(u_char &a, u_char b) {
    a = a | b;
}



#endif //INCLUDE_SERIAL_UTILS_H
